/**
 *
 */
Ext.define('vacake.controller.Category', {
    extend: 'Ext.app.Controller',
    config: {
        categoryId: '',
        refs: {
            mainView: 'mainView',
            categoryView: 'categoryView',
            allList: 'allList',
            classDataView: 'categoryView #class_data_view',
            priceList: 'allList #priceList',
            sellList: 'allList #sellList',
            popularityList: 'allList #popularityList',
            discountList: 'allList #discountList'
        },
        control: {
            classDataView: {
                itemtap: 'showClassifyList_onItemTap'
            }, priceList: {
                itemtap: 'productShowView'
            }, sellList: {
                itemtap: 'productShowView'
            }, popularityList: {
                itemtap: 'productShowView'
            }, discountList: {
                itemtap: 'productShowView'
            }
        }
    },

    showClassifyList_onItemTap: function (list, index, element, record) {
        Ext.Viewport.mask({
            xtype: 'loadmask',
            message: '加载数据中...'
        });
        this.setCategoryId(record.get('ccid'));
        var allistView = Ext.create("vacake.view.category.AllList");
        Ext.getCmp('alltitle').setTitle(record.get('name'));


        var productOrderPrice = Ext.getStore('ProductOrderPrice');
        var productOrderPop = Ext.getStore('ProductOrderPop');
        var productOrderSell = Ext.getStore('ProductOrderSell');
        var productOrderDis = Ext.getStore('ProductOrderDis');

        if (productOrderPrice.find('ccid', record.get('ccid')) == -1) {
            productOrderPrice.load({params: {ccid: this.getCategoryId(), order: 'meanPrice'}});
        }
        if (productOrderPop.find('ccid', record.get('ccid')) == -1) {
            productOrderPop.load({params: {ccid: this.getCategoryId(), order: 'viewnum'}});
        }
        if (productOrderSell.find('ccid', record.get('ccid')) == -1) {
            productOrderSell.load({params: {ccid: this.getCategoryId(), order: 'marketnum'}});
        }
        if (productOrderDis.find('ccid', record.get('ccid')) == -1) {
            productOrderDis.load({params: {ccid: this.getCategoryId(), order: 'rebate'}});
        } 

        Ext.Viewport.animateActiveItem(allistView, {type: 'slide', direction: 'left'});
    },
    productShowView: function (list, index, element, record) {
        Ext.Viewport.mask({
            xtype: 'loadmask',
            message: '加载数据中...'
        });
        this.redirectTo('loadProduct/' + record.get('cpid'));
    }

});

